/*
 * Copyright (C) 2007,2008  Jonathan Hendler
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 * 
 * The authors can be contacted at: 
 * @author Jonathan Hendler [jonathan DOT hendler AT google DOT com]
 * 
 * @license GPLv2
 */

#include "nymrl_conf.h"

inline char * _nymrl_conf_file_value(const char * key){
	FILE * conf_file;
	static char conf_value[MASTER_CONF_BUFFER_SIZE];
	conf_file = (FILE *) fopen( MASTER_CONF_FILENAME ,"r");
	char line[MASTER_CONF_LINE_SIZE+2];
	int count = 0;
	
	if (conf_file == NULL ){
		printf("Cant open config file master.conf.");
		return "";
	}
	
	while (fgets(line, MASTER_CONF_LINE_SIZE, conf_file) != NULL){
//		//read through each line
		count = sscanf(line,key,conf_value);
		if (count ==1){
			//printf("\n CONF*** found '%s'\n",conf_value);
			break;
		}
		
	}
	
	fclose(conf_file);
	return conf_value;
}

inline char * nymrl_conf_get_node_db(){
	return _nymrl_conf_file_value("nodedb=%[^;]");
}

inline char * nymrl_conf_get_log_db(){
	return _nymrl_conf_file_value("logdb=%[^;]");
}